import crypto from 'crypto'
import fs from 'fs'

export function genSha (path: string) {
  return new Promise((resolve, reject) => {
    const md5sum = crypto.createHash('md5')
    const stream = fs.createReadStream(path)
    stream.on('data', function (chunk) {
      md5sum.update(chunk)
    })
    stream.on('end', function () {
      resolve(md5sum.digest('hex').toUpperCase())
    })
    stream.on('error', err => reject(err))
  })
}
